'use strict';

const Controller = require("./base");
class MedicController extends Controller {
     
  // 通用的模糊分页查询排序语句 后期处理安全与权限问题
  async search() {
    const { ctx } = this;
    const { tableName='table1', page = 1, perPage = 10 } = ctx.query;
    const { query,order} = ctx.request.body
    const results = await this.app.mysql.query(`select * from ${tableName} ${this.getWhere({ query })} ${order?order:''} limit ${(page - 1) * perPage},${perPage}`);
    this.success(results); 
  }
  // 手动录入一条
  async create() {
    const { ctx } = this;  
    const result = await this.app.mysql.insert('table1', ctx.request.body); // 自己用自己知道前端传什么
    ctx.body = result;// leanclod 存储一样 前端自己写表
  }
}

module.exports = MedicController;
